package org.csu.bbs.service.impl;

import org.csu.bbs.entity.Comment;
import org.csu.bbs.persistence.CommentMapper;
import org.csu.bbs.result.Result;
import org.csu.bbs.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentMapper commentMapper;

    @Override
    public Result addComment(Comment comment) {
        try{
            if (comment.getReply().equals("")){
                comment.setReply(null);
            }
            System.out.println(comment);
            commentMapper.insert(comment);
            return new Result(200);
        } catch(Exception e){
            e.printStackTrace();
            return new Result(400);
        }
    }

    @Override
    public List<Comment> getComments(int postid) {
        try{
            return commentMapper.selectCommentByPostid(postid);
        } catch(Exception e){
            e.printStackTrace();
            return null;
        }
    }
}
